const app=new Vue({
  el:'#app',
  data:{
    books:[
      {
        id: 1,
        name: '局外人',
        price: 19.80,
        count: 1,
      },
      {
        id: 2,
        name: '福尔摩斯',
        price: 96.00,
        count: 1,
      },
      {
        id: 3,
        name: 'java从入门到精通',
        price: 71.20,
        count: 1,
      },
      {
        id: 4,
        name: 'it项目经理',
        price: 48.90,
        count: 1,
      },
    ]
  },
  methods:{
    decCount(index){
      this.books[index].count--
    },
    incCount(index){
      this.books[index].count++
    },
    removeHandler(index){
      this.books.splice(index,1)
    }
  },
  filters:{
    showPrice(price){
      return '¥ ' +price.toFixed(2)
    }
  },
  computed:{
    totalPrice(){
      return this.books.reduce((preValue,element)=>preValue+element.price*element.count,0)
    }
  }
})